<template>
    <div class="newsInfo">
        <div class="newsTitle">
            <h3>{{news.title}}</h3>
            <p>
                <span>发表时间:{{news.add_time | dateFormat}}</span>
                <span>点击: {{news.click}}次</span>
            </p>
        </div>
        <hr>
        <div v-html="news.content" class="content">
        </div>
        
        <comment :id=id></comment>
    </div>
</template>

<script>
import { Toast } from 'mint-ui'
import comment from '../subcomponent/comment.vue'
export default {
    data(){
        return {
            id: this.$route.params.newid,
            news:{}
        }
    },
    created(){
        this.getNew()
    },
    methods:{
        getNew(){
            
            this.$http.get('api/getnew/' + this.id).then(result=>{
                if(result.body.status === 0) { 
                    this.news = result.body.message[0]
                    // console.log(result.body.message)
                    this.news.content = this.news.content.replace(/src="[^"]+"/g, 'src="https://wx4.sinaimg.cn/large/4b9a6bfely1g1v7hujrv8j20gl0aqwer.jpg"')
                } else {
                    Toast('获取新闻信息失败')
                }
            })
        }
    },
    components:{
        comment
    }
}
</script>

<style lang="less">
    .newsInfo {
        padding: 0 5px;
        .newsTitle {
            h3 {
                color: red;
                text-align: center;
                font-size: 16px;
                line-height: 30px;
            }
            p {
                font-size: 14px;
                display: flex;
                justify-content:space-between;
                color: blue;
                
            }
            
        }
        .content{
                img {
                    width: 100%;
                }
            }

    }    
</style>